//
//  GoodsSiftView.m
//  WuJieLive
//
//  Created by haidong on 2017/12/25.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "GoodsSiftView.h"

@interface GoodsSiftView ()
{
    BOOL _isSelectedDown;
}
@property (weak, nonatomic) IBOutlet HDButton *normalBtn;
@property (weak, nonatomic) IBOutlet HDButton *saleBtn;
@property (weak, nonatomic) IBOutlet HDButton *priceBtn;
@property (weak, nonatomic) IBOutlet HDButton *siftBtn;

@end

@implementation GoodsSiftView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.normalBtn setTitleColor:TextMainColor forState:UIControlStateNormal];
    [self.normalBtn setTitleColor:MainColor forState:UIControlStateSelected];
    
    [self.saleBtn setTitleColor:TextMainColor forState:UIControlStateNormal];
    [self.saleBtn setTitleColor:MainColor forState:UIControlStateSelected];
    
    [self.priceBtn setTitleColor:TextMainColor forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:MainColor forState:UIControlStateSelected];
    [self.priceBtn setImage:[UIImage imageNamed:@"goods_img_trianglegroup_normal"] forState:UIControlStateNormal];
    [self.priceBtn setImage:[UIImage imageNamed:@"goods_img_trianglegroup_down"] forState:UIControlStateSelected];
    [self.priceBtn setButtonTitleWithImageAlignment:UIButtonTitleWithImageAlignmentLeft];
    
    [self.siftBtn setTitleColor:TextMainColor forState:UIControlStateNormal];
    [self.siftBtn setTitleColor:MainColor forState:UIControlStateSelected];
    [self.siftBtn setImage:[UIImage imageNamed:@"goods_img_sift_normal"] forState:UIControlStateNormal];
    [self.siftBtn setImage:[UIImage imageNamed:@"goods_img_sift_selected"] forState:UIControlStateSelected];
    [self.siftBtn setButtonTitleWithImageAlignment:UIButtonTitleWithImageAlignmentLeft];

    self.normalBtn.selected = YES;
}

- (IBAction)buttonAction:(HDButton *)sender {
    // 价格筛选
    if (sender.tag == 12) {
        if (sender.selected) {
            if (_isSelectedDown) {
                [sender setImage:[UIImage imageNamed:@"goods_img_trianglegroup_down"] forState:UIControlStateSelected];
                _isSelectedDown = NO;
            } else {
                [sender setImage:[UIImage imageNamed:@"goods_img_trianglegroup_up"] forState:UIControlStateSelected];
                _isSelectedDown = YES;
            }
            if (self.selectBlock) {
                self.selectBlock(sender.tag - 10, _isSelectedDown);
            }
        } else {
            [self refreshBtnState];
            [sender setImage:[UIImage imageNamed:@"goods_img_trianglegroup_down"] forState:UIControlStateSelected];
            sender.selected = YES;
            _isSelectedDown = NO;
            if (self.selectBlock) {
                self.selectBlock(sender.tag - 10, NO);
            }
        }
    } else {
        if (sender.selected) {
            return;
        }
        [self refreshBtnState];
        sender.selected = YES;
        if (self.selectBlock) {
            self.selectBlock(sender.tag - 10, NO);
        }
    }
    
}

- (void)refreshBtnState {
    self.normalBtn.selected = NO;
    self.saleBtn.selected = NO;
    self.priceBtn.selected = NO;
    [self.priceBtn setImage:[UIImage imageNamed:@"goods_img_trianglegroup_down"] forState:UIControlStateSelected];
    self.siftBtn.selected = NO;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
